#include <stdio.h>

#define N 1000

int a[N]; 
int n; 
int total; 
int avg; 

#define _pl()  printf("line=%d, i=%d, a[i]=%d, l=%d, r=%d, m=%d, should=%d, fact=%d, ret=%d\n", \
	__LINE__, i, a[i], l, r, m, should_be, in_fact, ret)

/* 
   Those two ranges are [l, mid) and [mid, r). One move is needed 
   exactly If it is imbalance between them, so we do the movement. 
*/ 
int move(int l, int r)
{
	int i=0, m=0, ret=0; 
	int diff, should_be=0, in_fact=0; 
	_pl(); 
	if (r-l<=1) {
		return ret; 
	}
	m = (l+r)/2; 
	should_be = 0; 
	in_fact = 0; 

	for(i=l; i<m; i++) {
		should_be += avg; 
		in_fact += a[i]; 
	}
	if (should_be==in_fact) {
		ret = 0; 
	} else {
		diff = should_be - in_fact; 
		a[m-1] += diff; 
		a[m] -= diff; 
		ret = 1; 
	}
	ret += move(l, m); 
	ret += move(m, r); 

	return ret; 
}

int main()
{
	int i, mv; 
	freopen("p1031_2.in", "r", stdin); 
	scanf("%d", &n);  
	for (i=0; i<n; i++) {
		scanf("%d", a+i); 
		total += a[i]; 
	}
	avg = total/n; 
	mv = move(0, n); 
	printf("%d\n", mv); 
	return 0; 
}

